#include "container.hpp"

using namespace Shiny;
using namespace Shiny::Widgets;

TextWidget::TextWidget() : Container()
{
  _typeCode        = type2code<TextWidget>::code;
}

void TextWidget::ResizeIfNeeded(void)
{
  //sf::Vector2f  size(GetWidth(), GetHeight());
  sf::FloatRect textRect = _text.GetGlobalBounds();
  sf::Vector2f  textSize;

  textSize.x = textRect.Left + textRect.Width;
  textSize.y = textRect.Top  + textRect.Height;
  SetSize(textSize);
}

void TextWidget::SetText(const std::string& str)
{
  sf::FloatRect rect;

  _text.SetString(str);
  rect = _text.GetLocalBounds();
  ResizeIfNeeded();
}

void TextWidget::SetFont(const sf::Font& font)
{
  _text.SetFont(font);
  ResizeIfNeeded();
}

void TextWidget::RenderSelf(void)
{
  Container::RenderSelf();
  this->Draw(_text);
}
